import type { PostLoginData } from '@/types/common'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
	'user',
	() => {
		const token = ref('')

		const setToken = (value: string) => {
			token.value = value
		}

		const clearToken = () => {
			token.value = ''
		}

		// 用户信息
		const userInfo = ref<PostLoginData>()

		const setUserInfo = (value: PostLoginData) => {
			userInfo.value = value
		}

		const clearUserInfo = () => {
			userInfo.value = undefined
		}

		return { token, setToken, clearToken, userInfo, setUserInfo, clearUserInfo }
	},
	{
		// 持久化
		persist: true
	}
)
